﻿@model UserModel
@using System.Text.Encodings.Web

<style type="text/css">
    .laytable-cell-1-AvatarUrl {
        height: 100%;
        max-width: 100%;
    }
</style>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="layui-form" wid200 lay-filter="">
                        <input asp-for="Id" type="hidden" />
                        <input asp-for="Approved" type="hidden" />
                        <input asp-for="Active" type="hidden" />
                        <input asp-for="Password" type="hidden" />
                        <input asp-for="AffiliateId" type="hidden" />
                        <input asp-for="ShopId" type="hidden" />
                        <div class="layui-form-item">
                            <u-label asp-for="UserGuid" />
                            <div class="layui-form-mid layui-word-aux">
                                @Html.Raw(Model.UserGuid)
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <u-label asp-for="Code" />
                            <div class="layui-form-mid layui-word-aux">
                                @Html.Raw(Model.Code)
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <u-label asp-for="Nickname" />
                            <div class="layui-input-inline">
                                <u-editor asp-for="Nickname" />
                                <span asp-validation-for="Nickname"></span>
                            </div>
                            @if (!string.IsNullOrEmpty(Model.AffilateName))
                            {
                                <div class="layui-form-mid layui-word-aux">
                                    (推荐人 @Model.AffilateName)
                                </div>
                            }
                        </div>
                        <div class="layui-form-item" style="display:@(Model.AllowManagingUserRoles?"block;":"none;")">
                            <u-label asp-for="SelectedUserRoleIds" />
                            <div class="layui-input-inline" style="width:20%;">
                                <u-select asp-for="SelectedUserRoleIds" asp-items="Model.AvailableUserRoles" asp-multiple="true" />
                                <span asp-validation-for="SelectedUserRoleIds"></span>
                            </div>
                            <div class="layui-form-mid layui-word-aux">
                                （可多选）
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <u-label asp-for="AvatarPictureId" />
                            <div class="layui-input-inline">
                                <u-editor asp-for="AvatarPictureId" />
                                <span asp-validation-for="AvatarPictureId"></span>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <u-label asp-for="PhoneNumber" />
                            <div class="layui-input-inline">
                                <u-editor asp-for="PhoneNumber" />
                                <span asp-validation-for="PhoneNumber"></span>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <u-label asp-for="Email" />
                            <div class="layui-input-inline">
                                <u-editor asp-for="Email" />
                                <span asp-validation-for="Email"></span>
                            </div>
                        </div>
                        @if (Model.Id > 0 && Model.AssociatedExternalAuthRecords.Count > 0)
                        {
                            <div class="layui-form-item">
                                <u-label asp-for="AssociatedExternalAuthRecords" />
                                <div class="layui-input-block" style="width:60%">
                                    <table id="LAY-user-list" lay-filter="LAY-user-list"></table>
                                    <script type="text/html" id="layuiadmin-app-cont-tagsbar">
                                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
                                    </script>
                                </div>
                                <script>
                                layui.use(['table'], function () {
                                        var index = layer.load(2, { shade: false });
                                        var table = layui.table
                                            , form = layui.form;
                                    //分类管理
                                    table.render({
                                        elem: '#LAY-user-list'
                                        , even: true
                                        , cols: [[
                                              { field: 'AuthMethodName', width: 150, style: 'height:80px;', title: '授权方式' }
                                            , { field: 'Name', title: '昵称', width: 100 }
                                            , { field: 'AvatarUrl', width: 110, style: 'height:100px;', title: '头像', templet: '<div><img height=80 src={{d.AvatarUrl}}></div>' }
                                            , { field: 'OpenId', title: 'OpenId', minWidth: 120, align: 'center' }
                                            , { title: '操作', width: 150, align: 'center',  toolbar: '#layuiadmin-app-cont-tagsbar' }
                                        ]]
                                        , data: [
                                            @for (int i = 0; i < Model.AssociatedExternalAuthRecords.Count; i++)
                                            {
                                                var aear = Model.AssociatedExternalAuthRecords[i];
                                                <text>
                                                   {
                                                        Id:@(aear.Id),
                                                        AuthMethodName: "@(Html.Raw(JavaScriptEncoder.Default.Encode(aear.AuthMethodName)))",
                                                        Name: "@(Html.Raw(aear.Name))",
                                                        AvatarUrl:"@(Html.Raw(aear.AvatarUrl))",
                                                        OpenId: "@(Html.Raw(JavaScriptEncoder.Default.Encode(aear.OpenId)))"
                                                    }
                                                </text>
                                                if (i != Model.AssociatedExternalAuthRecords.Count - 1)
                                                {
                                                    <text>,</text>
                                                }
                                            }
                                          ]
                                        , text: { none: '一条数据也没有^_^' }
                                        , done: function () {
                                            layer.close(index);
                                        }
                                    });
                                    //监听工具条
                                    table.on('tool(LAY-user-list)', function (obj) {
                                        var data = obj.data;
                                        if (obj.event === 'del') {
                                            layer.confirm('确定删除？', function (index) {
                                                obj.del();
                                                $.post('@Url.Action("ExternalAuthDelete")', { id: obj.data.Id });
                                                layer.close(index);
                                            });
                                        }
                                    });

                                    var $ = layui.$, active = { }
                                    $('.layui-btn.layuiadmin-btn-tags').on('click', function () {
                                        var type = $(this).data('type');
                                        active[type] ? active[type].call(this) : '';
                                    });
                                });
                                </script>
                            </div>
                        }
                        <div class="layui-form-item">
                            <u-label asp-for="AdminComment" />
                            <div class="layui-input-block">
                                <u-textarea asp-for="AdminComment"></u-textarea>
                                <span asp-validation-for="AdminComment"></span>
                            </div>
                        </div>
                        @if (Model.Id > 0)
                        {
                            <div class="layui-form-item">
                                <u-label asp-for="CreateTime" />
                                <div class="layui-form-mid layui-word-aux">
                                    @Html.Raw(Model.CreateTime)
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <u-label asp-for="LastActivityDate" />
                                <div class="layui-form-mid layui-word-aux">
                                    @Html.Raw(Model.LastActivityDate)
                                </div>
                            </div>
                        }
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="set_system_submit_btn">确认保存</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['index', 'laydate', 'upload','multiSelect'], function () {
        var $ = layui.$
            , form = layui.form
            , laydate = layui.laydate
            , upload = layui.upload
            , multiSelect = layui.multiSelect
            ,active = {}

        //日期
        laydate.render({
            elem: '#DateOfBirth'
        });

        //执行实例
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            , url: '/upload/' //上传接口
            , done: function (res) {
                //上传完毕回调
            }
            , error: function () {
                //请求异常回调
            }
        });

         var isclick = true;
            form.on('submit(set_system_submit_btn)', function (obj) {
            if (isclick) {
                isclick = false;
                var index = layer.load(2, { shade: false });
                var field = obj.field; //获取提交的字段
                var vals = [];
                $('select[multiple] option:selected').each(function () {
                    vals.push($(this).val());
                });
                field.SelectedUserRoleIds = vals;
                //layer.msg(JSON.stringify(obj.field));
                //提交 Ajax 成功后，关闭当前弹层并重载表格
                $.post('@Url.Action("Edit")', field, function (rep) {
                    if (rep.success == 1) {
                        layer.close(index);
                        isclick = true;
                        layer.msg("保存成功,即将自动关闭", { time: 2 * 1000 }, function () {
                            var iframe_index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            console.log("当前iframe层的索引:" + iframe_index + "==window.name:" + window.name);
                            parent.layer.close(iframe_index); //再执行关闭
                            window.parent.location.reload();
                        });
                    }
                });
            }
            return false;
        });
        $('.layui-btn.layuiadmin-btn-tags').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });
</script>





